using I2.Loc;
using UnityEngine;

public class MarketCarMiniInfoPanel : MarketMiniInfoPanel
{
	public UILabel accelerationCount;

	public UILabel controlCount;

	public UILabel speedCount;

	public UILabel strengthCount;

	public UILabel damageCount;

	public Color defaultTextColor;

	public Color improvedTextColor;

	public GameObject notForRace;

	public GameObject onlyForTitans;

	public GameObject accelerationGO;

	public GameObject damageGO;

	public UISprite carTypeSprite;

	public UILabel carTypeLabel;

	public UISprite rareTypeSprite;

	public UILabel rareTypeLabel;

	public void SetInfo(Product product)
	{
		currentProduct = product;
		ProductCar productCar = (ProductCar)product;
		strengthCount.text = CarCurrentParam(productCar, UpgradeType.Body);
		speedCount.text = CarCurrentParam(productCar, UpgradeType.Engine);
		if (currentProduct is ProductTank)
		{
			controlCount.text = CarCurrentParam(productCar, UpgradeType.Wheels);
			damageCount.text = CarCurrentParam(productCar, UpgradeType.Intake);
		}
		else
		{
			string s = CarCurrentParam(productCar, UpgradeType.Intake);
			string s2 = CarCurrentParam(productCar, UpgradeType.Wheels);
			int result = 0;
			int result2 = 0;
			int.TryParse(s, out result);
			int.TryParse(s2, out result2);
			controlCount.text = (result + result2).ToString();
		}
		strengthCount.color = defaultTextColor;
		speedCount.color = defaultTextColor;
		controlCount.color = defaultTextColor;
		if ((bool)damageCount)
		{
			damageCount.color = defaultTextColor;
		}
		SwitchInfoForVehicleType(productCar is ProductTank);
		if ((bool)onlyForTitans)
		{
			onlyForTitans.SetActive(false);
		}
		if ((bool)notForRace)
		{
			notForRace.SetActive(false);
		}
		if (productCar.onlyForTitans)
		{
			if ((bool)onlyForTitans)
			{
				onlyForTitans.SetActive(true);
			}
		}
		else if (productCar.notForRace && (bool)notForRace)
		{
			notForRace.SetActive(true);
		}
		if ((bool)MarketPreviewController.upgradePreviewer)
		{
			ProductVehicleSkin equipedVehicleSkin = MarketController.Instance.GetEquipedVehicleSkin(productCar.id);
			if (equipedVehicleSkin != null)
			{
				MarketPreviewController.upgradePreviewer.ShowSkin(Resources.Load<Texture>("AllCarSkins/" + equipedVehicleSkin.skinTextureName));
			}
			else
			{
				MarketPreviewController.upgradePreviewer.ShowDefault();
			}
		}
		if ((bool)carTypeSprite)
		{
			carTypeSprite.spriteName = "CarProductType_" + productCar.carType;
			carTypeLabel.text = ScriptLocalization.Get("Market/CarType_" + productCar.carType);
			carTypeSprite.gameObject.SetActive(true);
		}
		if ((bool)rareTypeSprite)
		{
			rareTypeSprite.spriteName = "RareType_" + productCar.rare;
			rareTypeLabel.text = ScriptLocalization.Get("Market/RareType_" + productCar.rare);
			rareTypeSprite.gameObject.SetActive(true);
		}
		SetTitleLocalization();
	}

	public void SetInfo(ProductVehicleUpgrade upgrade)
	{
		ProductCar productCar = (ProductCar)currentProduct;
		if (upgrade.Purchased && upgrade.nextProduct != null)
		{
			upgrade = upgrade.nextProduct as ProductVehicleUpgrade;
		}
		strengthCount.text = ((upgrade.upgradeType != 0) ? CarCurrentParam(productCar, UpgradeType.Body) : CarParam(productCar, UpgradeType.Body, upgrade.coef));
		speedCount.text = ((upgrade.upgradeType != UpgradeType.Engine) ? CarCurrentParam(productCar, UpgradeType.Engine) : CarParam(productCar, UpgradeType.Engine, upgrade.coef));
		strengthCount.color = ((upgrade.upgradeType != 0) ? defaultTextColor : improvedTextColor);
		speedCount.color = ((upgrade.upgradeType != UpgradeType.Engine) ? defaultTextColor : improvedTextColor);
		if (currentProduct is ProductTank)
		{
			controlCount.text = ((upgrade.upgradeType != UpgradeType.Wheels) ? CarCurrentParam(productCar, UpgradeType.Wheels) : CarParam(productCar, UpgradeType.Wheels, upgrade.coef));
			controlCount.color = ((upgrade.upgradeType != UpgradeType.Wheels) ? defaultTextColor : improvedTextColor);
			damageCount.text = ((upgrade.upgradeType != UpgradeType.Intake) ? CarCurrentParam(productCar, UpgradeType.Intake) : CarParam(productCar, UpgradeType.Intake, upgrade.coef));
			damageCount.color = ((upgrade.upgradeType != UpgradeType.Intake) ? defaultTextColor : improvedTextColor);
		}
		else
		{
			string s = ((upgrade.upgradeType != UpgradeType.Intake) ? CarCurrentParam(productCar, UpgradeType.Intake) : CarParam(productCar, UpgradeType.Intake, upgrade.coef));
			string s2 = ((upgrade.upgradeType != UpgradeType.Wheels) ? CarCurrentParam(productCar, UpgradeType.Wheels) : CarParam(productCar, UpgradeType.Wheels, upgrade.coef));
			int result = 0;
			int result2 = 0;
			int.TryParse(s, out result);
			int.TryParse(s2, out result2);
			controlCount.text = (result + result2).ToString();
			controlCount.color = ((upgrade.upgradeType != UpgradeType.Wheels && upgrade.upgradeType != UpgradeType.Intake) ? defaultTextColor : improvedTextColor);
		}
		SwitchInfoForVehicleType(productCar is ProductTank);
		if (notForRace != null)
		{
			if (productCar.notForRace)
			{
				if ((bool)notForRace)
				{
					notForRace.SetActive(true);
				}
			}
			else if ((bool)notForRace)
			{
				notForRace.SetActive(false);
			}
		}
		SetTitleLocalization();
		if ((bool)MarketPreviewController.upgradePreviewer)
		{
			MarketPreviewController.upgradePreviewer.ShowUpgradeOfType(upgrade.upgradeType, upgrade.FirstNotBuyedOrLastUpgradeNumber());
		}
	}

	private string CarCurrentParam(ProductCar car, UpgradeType type)
	{
		float carUpgradeCoef = MarketController.Instance.GetCarUpgradeCoef(car.id, type);
		return CarParam(car, type, carUpgradeCoef);
	}

	private string CarParam(ProductCar car, UpgradeType type, float coef)
	{
		bool flag = car is ProductTank;
		switch (type)
		{
		case UpgradeType.Body:
			return (car.strength * coef).ToString("F0");
		case UpgradeType.Engine:
			return (car.speed * coef).ToString("F0");
		case UpgradeType.Intake:
			return (((!flag) ? car.acceleration : (car as ProductTank).damage) * coef).ToString("F0");
		case UpgradeType.Wheels:
			return (car.control * coef).ToString("F0");
		default:
			return string.Empty;
		}
	}

	private void SwitchInfoForVehicleType(bool isTank)
	{
		if (!(damageGO != null))
		{
			return;
		}
		if (isTank)
		{
			damageGO.SetActive(true);
			if ((bool)damageCount)
			{
				damageCount.gameObject.SetActive(true);
			}
		}
		else
		{
			damageGO.SetActive(false);
			if ((bool)damageCount)
			{
				damageCount.gameObject.SetActive(false);
			}
		}
	}
}
